package com.client.clovece;
import java.awt.Dimension;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;

import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.JTextField;


public class InfoPanel extends JPanel{
	Dimension d, e;
	JTextArea text;
	JScrollPane scPane;
	JLabel l1, l2, l3, l4, l5;
	JCheckBox chx1, chx2, chx3, chx4;
	GridBagLayout g;
	GridBagConstraints c1, c2, c3, c4, c5, c6, c7, c8, c9;
	JButton skipButton;
	
	LocalGame parent;
	public InfoPanel(LocalGame parent, int numPls){
		this.parent = parent;
		d = new Dimension(520,55);
		setPreferredSize(d);
		setMinimumSize(d);
		setMaximumSize(d);
		g = new GridBagLayout();
		setLayout(g);
		initLeftPart();
		initMiddlePart();
		disableChecks(numPls);
		//initRightPart();
		setVisible(true);
	}
	
	private void disableChecks(int numPls){
		switch(numPls){
			case 2: chx3.setEnabled(false);
					chx4.setEnabled(false);
					break;
			case 3: chx4.setEnabled(false);
					break;					
		}
	}
	
	private void initLeftPart(){
		l1 = new JLabel("Nastaveni AI");
		chx1 = new JCheckBox("PL1");
		chx2 = new JCheckBox("PL2");
		chx3 = new JCheckBox("PL3");
		chx4 = new JCheckBox("PL4");
		
		chx1.addItemListener(parent);
		chx2.addItemListener(parent);
		chx3.addItemListener(parent);
		chx4.addItemListener(parent);
		
		c1 = new GridBagConstraints();
		//c1.fill = GridBagConstraints.BOTH;
		c1.gridx = 0;
		c1.gridy = 0;
		c1.gridheight = 1;
		c1.gridwidth = 2;
		c1.anchor = GridBagConstraints.CENTER;
		c1.insets = new Insets(0,0,0,30);
		add(l1,c1);
		
		c1.gridx = 0;
		c1.gridy = 1;
		c1.gridwidth = 1;
		c1.anchor = GridBagConstraints.WEST;
		add(chx1,c1);
		
		c1.gridx = 0;
		c1.gridy = 2;
		c1.gridwidth = 1;
		add(chx3, c1);
		
		//c1.insets = new Insets(0,0,0,10);
		c1.gridx = 1;
		c1.gridy = 1;
		c1.gridwidth = 1;
		add(chx2,c1);
		
		
		c1.gridx = 1;
		c1.gridy = 2;
		c1.gridwidth = 1;
		add(chx4, c1);
	}
	
	private void initMiddlePart(){
		l2 = new JLabel("Kostka");
		c2 = new GridBagConstraints();
		c2.insets = new Insets(0,0,0,22);
		c2.anchor = GridBagConstraints.CENTER;
		c2.gridx = 3;
		c2.gridy = 0;
		c2.gridwidth = 2;
		add(l2, c2);
		
		l3 = new JLabel();
		c2.gridy = 1;
		c2.gridheight = 2;
		add(l3, c2);
		//setDice();
		
		l4 = new JLabel("Na tahu");
		c2.gridx = 5;
		c2.gridy = 0;
		c2.gridheight = 1;
		c2.insets = new Insets(0,5,0,0);
		add(l4, c2);
		
		l5 = new JLabel();
		c2.gridx = 5;
		c2.gridy = 1;
		c2.gridheight = 2;
		add(l5, c2);
		//setActiveIcon();
		
		skipButton = new JButton("Preskocit");
		skipButton.addMouseListener(parent);
		c2.gridx = 7;
		c2.gridy = 0;
		c2.gridheight = 3;
		c2.insets = new Insets(0,20,0,0);
		add(skipButton, c2);
	}
	
	private void initRightPart(){
		e = new Dimension(200, 40);
		text = new JTextArea();
		scPane = new JScrollPane(text);
		c3 = new GridBagConstraints();
		c3.anchor = GridBagConstraints.LINE_END;
		c3.fill = GridBagConstraints.BOTH;
		c3.gridx = 7;
		c3.gridy = 0;
		c3.gridheight = 3;
		c3.gridwidth = 5;
		c3.insets = new Insets(0,33,0,0);
		text.setEditable(false);
		text.setColumns(20);
		text.setRows(5);
		text.append("Ahoj\n");
		text.setPreferredSize(e);
		text.setMinimumSize(e);
		text.setMaximumSize(d);
		add(text, c3);
	}
	
	public void setActiveIcon(ImageIcon i){
		l5.setIcon(i);
		l5.update(l5.getGraphics());
	}
	
	public void setDice(ImageIcon i){
		l3.setIcon(null);
		l3.setIcon(i);
		l3.update(l3.getGraphics());
		
	}
	
	
	public void write(String s){
		text.append(s+"\n");
	}
}
